package com.itheima.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.MemberService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
public class MemberController {
    @Reference
    private MemberService memberService;
    @PostMapping("report/getMemberCountAndYear")
    public Result getMemberCountAndYear() {
        try {
            Map<String, List> map = memberService.getMemberCountAndYear();

            return new Result(true, "查询统计成功",map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询统计失败");
        }
    }

    @PostMapping("report/getMemberCount")
    public Result getMemberCount(@RequestBody String[] dateArray) {
        try {
            /*
                前端已json格式发送  key  value
                map为key  value  格式
             */
            Map<String, List> map = memberService.getMemberCount(dateArray);

            return new Result(true, "按日期段查询成功",map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "按日期段查询失败");
        }
    }
//    @GetMapping("member/countMemberBySexAndAge")
//    public Result countMemberBySexAndAge(){
//        try {
//            List<Map> mapList=memberService.countMemberBySexAndAge();
//            return new Result(true,"按性别年龄查询成功");
//        } catch (Exception e) {
//            return new Result(false,"按性别年龄查询失败");
//        }
//    }
}
